Answer:

No — usually all the instance variables are declared in one place in the class definition and it is easy to check them.

Method Overloading

Overloading is when two or more methods of a class have the same name but have different parameter lists. When a method is called, the correct method is picked by matching the actual parameters in the call to the formal parameter lists of the methods.

Review: another use of the term "overloading" is when an operator calls for different operations depending on its operands. For example + can mean integer addition or string concatenation depending on its operands.

Say that two processDeposit() methods were needed:

class CheckingAccount
{
  . . . .
  private int    balance;

  . . . .
  void  processDeposit( int amount )
  {
    balance = balance + amount ; 
  }

  void  processDeposit( int amount, int serviceCharge )
  {
    balance = balance + amount - serviceCharge; 
  }

}

The above code implements these requirements. Here is an example main() method that uses both methods:

class CheckingAccountTester
{
  public static void main( String[] args )
  {
    CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );
    bobsAccount.processDeposit( 200 );       // statement A
    bobsAccount.processDeposit( 200, 25 );   // statement B
  }
}

QUESTION 12:

Which method, processDeposit(int) or processDeposit(int, int) does each statement call?

  1. statement A calls
  2. statement B calls